<template>
   <el-form :inline="true" :model="searchObj" class="demo-form-inline">
    <el-form-item v-for="(item,index) in searchList" :label="item.label" :key="index" >
         <template  v-if="item.type=='select'">
            <el-select v-model="searchObj[item.name]" :placeholder="item.label" clearable>
                <el-option v-for="(opt,index2) in item.options" :key="index2" 
                :label="opt.label || opt[item.labelName.label]" 
                :value="opt.value || opt[item.labelName.value]" > </el-option>

            </el-select> 
        </template>

         <template  v-else>
            <el-input v-model="searchObj[item.name]" :placeholder="item.label" clearable></el-input>
        </template>
   </el-form-item>

   
      <!-- <el-form-item label="昵称">
         <el-input v-model="searchObj.nickname" placeholder="昵称" clearable></el-input>
      </el-form-item>
      <el-form-item label="性别">
         <el-select v-model="searchObj.gender" placeholder="性别" clearable>
            <el-option label="男" value="1"></el-option>
            <el-option label="女" value="0"></el-option>
         </el-select>  
      </el-form-item>
      <el-form-item label="手机号">
         <el-input v-model="searchObj.phone" placeholder="手机号" clearable></el-input>
      </el-form-item>  -->
      <el-form-item>
         <el-button type="primary" @click="onSubmitSearch">查询</el-button>
      </el-form-item>
      </el-form>
</template>

<script>
import axiosEl from '@/utils/axios';
export default {
    props:{
        searchList:Array
    },
    data(){
        return {
            searchObj:{}
        }
    },
    methods:{
        onSubmitSearch(){
            // searchObj 给父组件
            this.$emit('search',this.searchObj)
        }
    },
    mounted(){
       let actionList =  this.searchList.filter((option)=>{
            return option.action
        })
        actionList.forEach(async (item)=>{
             const {method='get',url} = item.action;
             let resData = await axiosEl({
                    method,
                    url
                })
                if(resData.code==1){
                    item.options = resData.data;
                    this.$forceUpdate();
                }           
        })

    }
}
</script>

<style>

</style>